import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model - 数据组管理
 * @date: 2019/4/16
 */
import { getResponse, createPagination } from 'utils/utils';
import { queryList, queryLineList, queryModalList, queryDataGroupHead, queryValueModalList, queryAssignedValueList, createDataGroup as _createDataGroup, createAssignedValue as _createAssignedValue, createDataGroupLine as _createDataGroupLine, deleteDataGroupLine as _deleteDataGroupLine, deleteAssignedValue as _deleteAssignedValue, updateDataGroupHead as _updateDataGroupHead } from "../services/dataGroupService";
export default {
  namespace: 'dataGroup',
  // model名称
  state: {
    dataGroupList: [],
    // 数据组列表
    pagination: {},
    // 数据组列表分页参数
    lineList: [],
    // 数据组行列表
    linePagination: {},
    // 数据组行列表分页
    assignedValueList: [],
    // 分配值列表
    assignedValuePagination: {},
    // 分配值分页
    dataGroupHeadInfo: {},
    // 数据组头信息
    createDataSource: [],
    // 新建数据组行的弹窗列表数据
    createPagination: {},
    // 新建数据组行的弹窗列表分页
    valueDataSource: [],
    // 新建数据组值的弹窗列表数据
    valuePagination: {} // 新建数据组值的弹窗列表分页

  },
  effects: {
    // 查询数据组列表
    fetchDataGroupList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchDataGroupList(_ref, _ref2) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchDataGroupList$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.next = 4;
              return call(queryList, payload);

            case 4:
              result = _context.sent;
              result = getResponse(result);

              if (!result) {
                _context.next = 9;
                break;
              }

              _context.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  dataGroupList: result.content,
                  pagination: createPagination(result)
                }
              });

            case 9:
            case "end":
              return _context.stop();
          }
        }
      }, fetchDataGroupList);
    }),
    // 新建数据组
    createDataGroup: /*#__PURE__*/_regeneratorRuntime.mark(function createDataGroup(_ref3, _ref4) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function createDataGroup$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.next = 4;
              return call(_createDataGroup, payload);

            case 4:
              response = _context2.sent;
              return _context2.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context2.stop();
          }
        }
      }, createDataGroup);
    }),
    // 查询数据组头信息
    fetchDataGroupHead: /*#__PURE__*/_regeneratorRuntime.mark(function fetchDataGroupHead(_ref5, _ref6) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchDataGroupHead$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call, put = _ref6.put;
              _context3.next = 4;
              return call(queryDataGroupHead, payload);

            case 4:
              result = _context3.sent;
              result = getResponse(result);

              if (!result) {
                _context3.next = 9;
                break;
              }

              _context3.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  dataGroupHeadInfo: result
                }
              });

            case 9:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchDataGroupHead);
    }),
    // 更新数据组头信息
    updateDataGroupHead: /*#__PURE__*/_regeneratorRuntime.mark(function updateDataGroupHead(_ref7, _ref8) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function updateDataGroupHead$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              _context4.next = 4;
              return call(_updateDataGroupHead, payload);

            case 4:
              result = _context4.sent;
              return _context4.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, updateDataGroupHead);
    }),
    // 查询数据组行列表数据
    fetchDataGroupLineList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchDataGroupLineList(_ref9, _ref10) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchDataGroupLineList$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call, put = _ref10.put;
              _context5.next = 4;
              return call(queryLineList, payload);

            case 4:
              result = _context5.sent;
              result = getResponse(result);

              if (!result) {
                _context5.next = 9;
                break;
              }

              _context5.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  lineList: result.content,
                  linePagination: createPagination(result)
                }
              });

            case 9:
            case "end":
              return _context5.stop();
          }
        }
      }, fetchDataGroupLineList);
    }),
    // 获取选择维度代码弹窗数据
    fetchModalData: /*#__PURE__*/_regeneratorRuntime.mark(function fetchModalData(_ref11, _ref12) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchModalData$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call, put = _ref12.put;
              _context6.next = 4;
              return call(queryModalList, payload);

            case 4:
              result = _context6.sent;
              result = getResponse(result);

              if (!result) {
                _context6.next = 9;
                break;
              }

              _context6.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  createDataSource: result.content,
                  createPagination: createPagination(result)
                }
              });

            case 9:
            case "end":
              return _context6.stop();
          }
        }
      }, fetchModalData);
    }),
    // 新建数据组行
    createDataGroupLine: /*#__PURE__*/_regeneratorRuntime.mark(function createDataGroupLine(_ref13, _ref14) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function createDataGroupLine$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref13.payload;
              call = _ref14.call;
              _context7.next = 4;
              return call(_createDataGroupLine, payload);

            case 4:
              response = _context7.sent;
              return _context7.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, createDataGroupLine);
    }),
    // 删除数据组行
    deleteDataGroupLine: /*#__PURE__*/_regeneratorRuntime.mark(function deleteDataGroupLine(_ref15, _ref16) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function deleteDataGroupLine$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref15.payload;
              call = _ref16.call;
              _context8.next = 4;
              return call(_deleteDataGroupLine, payload);

            case 4:
              result = _context8.sent;
              return _context8.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context8.stop();
          }
        }
      }, deleteDataGroupLine);
    }),
    // 查询分配值列表
    fetchAssignedValueList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchAssignedValueList(_ref17, _ref18) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchAssignedValueList$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref17.payload;
              call = _ref18.call, put = _ref18.put;
              _context9.next = 4;
              return call(queryAssignedValueList, payload);

            case 4:
              result = _context9.sent;
              result = getResponse(result);

              if (!result) {
                _context9.next = 9;
                break;
              }

              _context9.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  assignedValueList: result.content,
                  assignedValuePagination: createPagination(result)
                }
              });

            case 9:
            case "end":
              return _context9.stop();
          }
        }
      }, fetchAssignedValueList);
    }),
    // 查询选择维度值的弹窗数据
    fetchValueModalData: /*#__PURE__*/_regeneratorRuntime.mark(function fetchValueModalData(_ref19, _ref20) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchValueModalData$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref19.payload;
              call = _ref20.call, put = _ref20.put;
              _context10.next = 4;
              return call(queryValueModalList, payload);

            case 4:
              result = _context10.sent;
              result = getResponse(result);

              if (!result) {
                _context10.next = 9;
                break;
              }

              _context10.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  valueDataSource: result.content,
                  valuePagination: createPagination(result)
                }
              });

            case 9:
            case "end":
              return _context10.stop();
          }
        }
      }, fetchValueModalData);
    }),
    // 新建分配值
    createAssignedValue: /*#__PURE__*/_regeneratorRuntime.mark(function createAssignedValue(_ref21, _ref22) {
      var payload, call, response;
      return _regeneratorRuntime.wrap(function createAssignedValue$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              payload = _ref21.payload;
              call = _ref22.call;
              _context11.next = 4;
              return call(_createAssignedValue, payload);

            case 4:
              response = _context11.sent;
              return _context11.abrupt("return", getResponse(response));

            case 6:
            case "end":
              return _context11.stop();
          }
        }
      }, createAssignedValue);
    }),
    // 删除分配值
    deleteAssignedValue: /*#__PURE__*/_regeneratorRuntime.mark(function deleteAssignedValue(_ref23, _ref24) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function deleteAssignedValue$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              payload = _ref23.payload;
              call = _ref24.call;
              _context12.next = 4;
              return call(_deleteAssignedValue, payload);

            case 4:
              result = _context12.sent;
              return _context12.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context12.stop();
          }
        }
      }, deleteAssignedValue);
    })
  },
  reducers: {
    // 合并state状态数据,生成新的state
    updateState: function updateState(state, _ref25) {
      var payload = _ref25.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};